/**
 * Created Date: Monday, October 23rd 2023, 6:15:27 pm
 * Author: CodingGorit
 * -----
 * Last Modified: Mon Oct 23 2023
 * Modified By: CodingGorit
 * -----
 * Copyright © 2019 —— 2023 fmin-courses TP Center All Rights Reserved
 * ------------------------------------
 * Javascript will save your soul!
 */

// 使用 createApp 来动态创建组件实例
import { createApp } from 'vue';
import { MessageType } from '@/types/components';
import Message from './Message.vue';

const createMessage = (message: string, type: MessageType, timeout = 2500) => {
    const messageInstance = createApp(Message, {
        message,
        type
    });
    const mountNode = document.createElement('div');
    document.body.appendChild(mountNode);
    messageInstance.mount(mountNode);

    setTimeout(() => {
        messageInstance.unmount();
        document.body.removeChild(mountNode);
    }, timeout);
}

export default createMessage;